﻿using System;
using System.Net;
using System.Collections.Generic;

namespace SCG.SolarVengeanceEngine
{
    //calculate the cost to build a StarShip
    public static class ShipCostCalculator
    {
        public static int GetCost(StarShipType shipType, int engines, int primary, bool cloaked, StarSystem system)
        {
            //calculate cost
            double cost = shipType.GetBaseCost();
            if (shipType.GetFixedEngines() == 0)
                for (int e = 1; e <= engines; e++)
                    for (int i = 1; i <= e; i++)
                        cost += ENGINE_COST;
            if (shipType.GetPrimarySystemName() != "")
                for (int i = 1; i <= primary; i++)
                    cost += (int)((double)i * shipType.GetCostMultiple());
            if (cloaked)
                cost *= 2.0d;
            int result = (int)cost;
            if (system != null && system.BonusValue > 0 && system.BonusShipType == shipType)
                result = (int)Math.Round(result * ((100.0d - system.BonusValue) / 100.0d));
            return result;
        }

        //private members        
        private static double ENGINE_COST = 4.0d / 20.0d;

    }
}
